import pandas as pd

def convert_to_days(gestational_week):
    """
    将孕周字符串（如 '11w+6' 或 '13w'）转换为天数。
    """
    if pd.isna(gestational_week):
        return None
    try:
        if 'w+' in gestational_week:
            parts = gestational_week.split('w+')
            weeks = int(parts[0])
            days = int(parts[1])
            return weeks*1.0 + days*1.0/7
        elif 'w' in gestational_week:
            parts = gestational_week.split('w')
            weeks = int(parts[0])
            return weeks
        else:
            return None
    except (ValueError, IndexError):
        return None



if __name__ == "__main__":
    df = pd.read_excel('data.xlsx')
    df['检测孕周（小数）'] = df['检测孕周'].apply(convert_to_days)
    print(df)
    df.to_excel('data_after_process.xlsx', index=False)
